<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">
		<meta http-equiv="pragma" content="no-cache">
		<script type="text/javascript" src="js/tools/jquery-1.4.2.min.js"></script>
<script charset="utf-8" src="js/tools/editor/kindeditor-min.js"></script>
<style>
table {table-layout: fixed;font-size: 12px;}
tr {background-color: #F1F6F6;}
td {border: 1px solid #D9D9D9;color: black;padding: 2px;}
#allTargs a {text-decoration: none;table-layout: fixed;font-size: 14px;margin-right: 8px;}
#keyword a {text-decoration: none;table-layout: fixed;font-size: 14px;margin-right: 8px;}
</style>
<script type="text/javascript">
$(function(){
	KE.show({
				id : 'content',
				resizeMode : 1,
				imageUploadJson : 'ajax/uploadimage!uploadImageForEditor.action'
			});
	$("input[type='checkbox']").click(function(){
	  if( $(this).attr("checked"))
	  {
	    $("#cont").hide();
	  }else
	  {
	    $("#cont").show();
	  }
	});
	var isNav='<s:property value="websiteColumn.isNav"/>';
	if(isNav==1)
	{
	  $("input[type='checkbox']").attr("checked",true);
	  $("#cont").hide();
	}
});
function check()
{

   var columnNameCn=$.trim($("input[name='columnNameCn']").val());
    var columnNameEn=$.trim($("input[name='columnNameEn']").val());
   var url=$.trim($("input[name='url']").val());
   var isNav=($("input[type='checkbox']").attr("checked")==true)?1:0;
   var content=$.trim($("#content").val());
   if(columnNameCn.length<1||columnNameCn.length>21)
   {
     $("#columnNameCn").css({"border": "2px solid red"});
      alert("栏目名称中文的长度为1~20");
      return false;
   }
   if(columnNameEn.length<1||columnNameEn.length>21)
   {
   
     $("#columnNameEn").css({"border": "2px solid red"});
      alert("栏目名称英文的长度为1~20");
      return false;
   }
	var reg=/^[a-zA-Z0-9_]+$/ ;
	if(!reg.test(columnNameEn) )
		{
		   alert("只能由英文字母、数字或下划线组成");
		  $("#columnNameEn").css({"border": "2px solid red"});
		  return false;
		}
   if(url.length<1||url.length>30)
   {
     $("#url").css({"border": "2px solid red"});
      alert("URL的长度为1~30");
      return false;
   }
   if(!reg.test(url) )
		{
		   alert("只能由英文字母、数字或下划线组成");
		  $("#columnNameEn").css({"border": "2px solid red"});
		  return false;
		}
   $("#columnNameCn,#columnNameEn,#url").css("border");
   var id='<s:property value="websiteColumn.id"/>';
   var param={};
       param["websiteColumn.columnNameCn"]=encodeURI(columnNameCn);
       param["websiteColumn.columnNameEn"]=encodeURI(columnNameEn);
       param["websiteColumn.url"]=url;
       param["websiteColumn.isNav"]=isNav;
       param["websiteColumn.sort"]=1;
       if(isNav==0)
       {
          param["websiteColumn.content"]=encodeURI(content);
       }
       var url="ajax/website!addColumn.action";
        var info="添加";
       if(id!="")
       {
           param["websiteColumn.id"]=id;
           url="ajax/website!modifyColumn.action";
           info="修改"
       }
       $.getJSON(url,param,function(data){
          if(data.info)
          {
            alert(info+"成功");
            window.location.href="admin/websitecolumn.jsp";
          }else
          {
            alert(info+"失败");
          }
       });
   return false;
};
</script>
	</head>
	<body>
		<table style="width: 98%;" align="center">
			<tr><td width="10%">栏目名称中文</td><td><input type="text" name=url id="url" value=""/></td></tr>
			<tr><td>栏目名称英文</td><td><input type="text" name=url id="url" value=""/></td></tr>
			<tr><td>URL</td><td><input type="text" name=url id="url" value=""/></td></tr>
			<tr><td>是否显示在主导航</td><td><input type="text" name=url id="url" value=""/></td></tr>
			<tr><td>单页或列表</td><td><input type="text" name=url id="url" value=""/> </td></tr>
			<tr><td>排序</td><td><input type="text" name=url id="url" value=""/> </td></tr>
			<tr><td><input type="button" onclick="check()" value="保存"/></td><td><input type="button" onclick="window.location.href='admin/websitecolumn.jsp';" value="返回"/></td></tr>
		</table>
	</body>
</html>
